package jude.java.money.test.init;

import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import jude.java.framework.test.SpringTestCase;
import jude.java.money.beans.Site;
import jude.java.money.service.DB;
import jude.java.util.FileUtils;
import jude.java.util.I;

public class InitScanFtp extends SpringTestCase {
	
	/**
	 * Site.hbm.xml 文件中表改为 tb_site2
	 * ScanFtp.hbm.xml 文件中表改为 tb_ftp2
	 * */
	public void testInitSite2() {
		String filePath = "M:\\Users\\Jude\\Desktop\\QQRecv\\heiliang8\\8.28.txt";
		String siteRegexp = "http://(?:www\\.)?([\\w\\.\\-_]{4,50})";
		StringBuilder sb = FileUtils.readFile(new File(filePath), "ISO-8859-1");
		int start = 0;
		Pattern p = Pattern.compile(siteRegexp);
		Matcher m = p.matcher(sb);
//		ScanService service = Services.getScanService();
		while (m.find(start)) {
			String host = m.group(1);
			System.out.println(host);
			Site site = new Site(host);
			if (DB.ntInsert(site)){
				I.success();
			} else {
				System.out.println("\t" + host);
			}
			I.total();
			start = m.end(0);
		}
		System.out.println(I.stat());
	}

}
